1. Field of the Invention
The present invention relates to the management of caches in a data processing apparatus, and in particular to the management of caches of the type where data in the cache may be associated with different types of memory region, and where the technique used to synchronise the contents of the cache with corresponding entries in the memory differs dependent on the memory region.
2. Description of the Prior Art
A cache may be arranged to store data and/or instructions so that they are subsequently readily accessible by a processor. Hereafter, the term xe2x80x9cdata valuexe2x80x9d will be used to refer to both instructions and data.
A number of different techniques have been developed for synchronising the contents of a cache with the contents of a memory, such as an off-chip main memory. For example, data values in the cache may be from a xe2x80x9cwrite throughxe2x80x9d region of memory, in which case whenever a data value stored in a cache line is updated by a new data value, then that new data value is also at that time output to memory, thereby maintaining synchronisation between the data values in the cache and the data values in the memory.
Another known type of memory region is referred to as a xe2x80x9cwrite backxe2x80x9d region. If a cache is arranged to store data values from a write back memory region, then when a data value in a cache line is updated by a new data value, a xe2x80x9cdirty bitxe2x80x9d associated with that cache line is set to indicate that the data value has been updated. However, no action is taken at that time to update the entry in the memory. Then, when that cache line is flushed from the cache, for example to make way for a different data value to be stored in the cache, then the xe2x80x9cdirty bitxe2x80x9d is evaluated to determine whether any data values stored at that cache line have been updated, and if so, the data values in the cache line are then output to the memory for storage to maintain coherency.
It is becoming common to allow a cache to store data values from different regions of memory, and hence the synchronization technique employed for any particular entry in the cache will depend on the memory region associated with that entry. Hence, for example, for some data values in the cache the above-mentioned write back technique may need to be employed, whilst for other data values in the cache, the above-mentioned write through technique may need to be employed.
Whilst this development provides improved flexibility, it increases the overhead required to effectively manage the cache. In particular, when the cache determines that a new data value output by the processor core is to update a data value at a particular cache line, a protection unit provided within the data processing apparatus needs to determine in which memory region that data value is contained, and to notify the cache accordingly to ensure that the cache correctly updates the cache line. For example, if the data value is in a write through region, then the dirty bit should not be set, since the new data value will also be provided directly to the memory for storage. In contrast, if the data value is in a write back region, then the dirty bit should be set, since the new data value will not be provided directly to the memory for storage, but will only be provided later when that data value is flushed from the cache.
It has been found that the time taken by the protection unit to provide this information to the cache adversely affects the speed with which the cache can be updated, this having a knock-on effect on the efficiency of the processor core, since typically the processor core cannot begin processing the next instruction until the update to the cache has occurred.
It will be appreciated that the protection unit can be embodied as a specific logical element for controlling access to memory regions, or alternatively the function of the protection unit can be provided by a more complex logical element such as a Memory Management Unit (MMU) which can be arranged to perform additional functions. For the purposes of the present application, both of the above will be referred to as a protection unit.
It is an object of the present invention to provide an improved technique for managing caches.
Accordingly, the present invention provides a data processing apparatus, comprising: a cache having a plurality of cache lines for storing data values retrieved from a plurality of memory regions of a memory, a first memory region being such that when a data value from that first memory region is stored in the cache and is subsequently updated within the cache by a new data value, the new data value is not transferred to memory until that new data value is removed from the cache; a marker associated with each cache line and being settable to indicate that the data values stored in the corresponding cache line are from said first memory region; a protection unit for determining control parameters for controlling the transfer of data values between the cache and the memory, and being arranged, when said data values are to be loaded from the memory into a cache line of the cache, to determine whether said data values are from said first memory region and to cause the marker to be set accordingly; and a processor core arranged to output a new data value for storage; the cache being arranged to determine if the new data value output by the processor core is to replace a data value stored in a cache line of the cache, and if so to update the corresponding cache line with the new data value, and to apply predetermined criteria to determine whether to set an update identifier indicating that the data value has been updated by the new data value, such that when the new data value is subsequently removed from the cache it can be determined whether to transfer that new data value to the memory.
In accordance with the present invention, a marker is associated with each cache line, which is settable to indicate that the data values stored in the corresponding cache line are from a first memory region, and the protection unit is then adapted to determine whether those data values are in the first memory region at the time that that cache line is initially loaded with those data values from memory, and to cause the marker to be set accordingly. By this approach, when the corresponding cache line is updated with a new data value, the cache can apply predetermined criteria to determine whether to set an update identifier indicating that the data value has been updated, without having to wait for any input from the protection unit. This approach effectively removes the critical path of deciding at the time of the cache line update whether the data value is in the first memory region, and thus the efficiency of the data processing apparatus can be significantly improved.
The new data value output by the processor core may be derived from the corresponding data value as previously stored, or may be an entirely new data value derived without reference to the corresponding data value as previously stored. The data value is considered here to be xe2x80x98newxe2x80x99 in the sense that it is more recent than the data value for that address stored in either the cache or the memory.
The predetermined criteria applied by the cache at the time of updating the cache line can take a number of different forms. In one embodiment, the predetermined criteria identify that the update identifier should be set if the marker is set, whereby when the new data value is subsequently removed from the cache, the update identifier is used to determine whether to transfer that new data value to the memory. Considering the earlier example of a memory containing both a write back region and a write through region, this approach ensures that the update identifier is only set when new data values stored in the cache are from the write back region of memory, the update identifier not being set when new data values stored in the cache are from the write through region. Hence, the result is the same as that which would be achieved using the earlier identified prior art technique, but without the delay introduced by having to employ the protection unit to instruct the cache at the time of the cache line update.
In an alternative embodiment, the predetermined criteria identify that the update identifier should be set whenever a data value associated with that update identifier is updated, whereby when the new data value is subsequently removed from the cache, the update identifier is used in combination with the marker to determine whether to transfer that new data value to the memory. By this approach, the cache always sets the update identifier when a new data value is stored in the cache, irrespective of the memory region associated with that data value, and the update identifier is then used in combination with the marker at the time that a particular cache line is flushed from the cache to determine whether to transfer the new data value to the memory. The new data value will be transferred to the memory in situations where both the update identifier and the marker are set.
The marker can take a variety of forms. However, in preferred embodiments, the marker comprises a marker field provided in the cache for each cache line, the marker for a particular cache line being set by storing a predetermined logic value in the corresponding marker field. Preferably, each marker field comprises a single bit, and hence the predetermined logic value used to set the marker may be a logic zero or a logic one value. In the preferred embodiment, the predetermined logic value is a logic one value.
As with the marker, the update identifier can also take a number of forms. However, in preferred embodiments, the update identifier comprises a dirty field provided in the cache for each cache line, the update identifier for a particular cache line being set by storing a predetermined logic value in the corresponding dirty field. Preferably, each dirty field comprises a single bit, and hence the predetermined logic value may be a logic zero or a logic one value. In the preferred embodiment, the predetermined logic value is a logic one value.
It will be appreciated that the present invention is applicable to caches that store data values from a memory having a variety of different memory regions. However, in preferred embodiments, the first memory region is a xe2x80x9cwrite backxe2x80x9d region, and at least one further memory region is a xe2x80x9cwrite throughxe2x80x9d region.
In preferred embodiments, each cache line of the cache will be arranged to store data values of a specified length. It is possible, for example, that a cache line may be arranged to store a single data word. However, in preferred embodiments, each cache line is arranged to store a plurality of data values, each data value stored in a cache line comprising a data word.
In preferred embodiments, the cache further comprises a validity identifier associated with each cache line which is set to confirm that the data values stored in the corresponding cache line are valid, and is resettable to indicate that at least one of the data values stored in the corresponding cache line has been invalidated. In accordance with the earlier mentioned embodiment, wherein when a new data value is stored in the cache, the update identifier is only set if the marker is set, then the validity identifier is used in combination with the update identifier to determine whether to transfer the new data value to the memory. If the new data value is invalid, then in preferred embodiments it is not output to the memory for storage. In the alternative embodiment where the update identifier is always set when a new data value is stored in the cache, irrespective of the value of the marker, then the validity identifier is used in combination with the marker and the update identifier to determine whether to transfer the new data value to the memory.
The validity identifier preferably takes the form of a valid field provided in the cache for each cache line, the validity identifier for a particular cache line being set by storing a predetermined logic value in the corresponding valid field. Preferably, each valid field comprises a single bit, and hence the predetermined logic value used to indicate that the corresponding data value is valid may be a logic zero or a logic one value. In the preferred embodiment, the predetermined logic value is a logic one value.
Viewed from a second aspect, the present invention provides a method of managing a cache in a data processing apparatus, the cache having a plurality of cache lines for storing data values retrieved from a plurality of memory regions of a memory, a first memory region being such that when a data value from that first memory region is stored in the cache and is subsequently updated within the cache by a new data value, the new data value is not transferred to memory until that new data value is removed from the cache, the method comprising the steps of: (a) providing a marker associated with each cache line which is settable to indicate that the data values stored in the corresponding cache line are from said first memory region; (b) when said data values are to be loaded from the memory into a cache line of the cache, determining whether said data values are from said first memory region; (c) setting the marker dependent on the determination at said step (b); (d) determining if a new data value is to replace a data value stored in a cache line of the cache, and if so updating the corresponding cache line with the new data value; and (e) upon updating the corresponding cache line with the new data value, applying predetermined criteria to determine whether to set an update identifier indicating that the data value has been updated, such that when the new data value is subsequently removed from the cache it can be determined whether to transfer that new data value to the memory.